﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Clipping.Infrastructure.Models
{
    public class ClassInfo
    {
        private string _id;
        private string _name;
        private List<ClassInfo> _subclasses = new List<ClassInfo>();

        public ClassInfo(string id, string name)
        {
            this._id = id;
            this._name = name;
        }
        /// <summary>
        /// 获取客户ID
        /// </summary>
        public string Id
        {
            get { return _id; }
        }
        /// <summary>
        /// 获取客户名
        /// </summary>
        public string Name
        {
            get { return _name; }
        }
        /// <summary>
        /// 获取子类信息
        /// </summary>
        public List<ClassInfo> SubClasses
        {
            get { return this._subclasses; }
        }
        /// <summary>
        /// 添加子类
        /// </summary>
        /// <param name="classinfo"></param>
        public void AddSubClasses(ClassInfo classinfo)
        {
            classinfo.ParentClass = this;
            this._subclasses.Add(classinfo);
        }

        public ClassInfo ParentClass
        {
            get;
            set;
        }

        ClientInfo client;
        public ClientInfo Client
        {
            get { return client; }
            set 
            {
                this.client = value;
                if (this._subclasses != null)
                {
                    foreach (var subC in this._subclasses)
                        subC.Client = value;
                }
            }
        }

        public string FullPath
        {
            get { return string.Format("[{0}]{1}", Client.Name, this.ToString()); }
        }

        public override string ToString()
        {
            string rtn = this.Name;
            if (this.ParentClass != null)
                rtn = string.Format("{0}>>{1}", this.ParentClass.ToString(), this.Name);
            return rtn;
        }
    }

}
